/**
 * ZhiZun.com Inc.
 * Copyright (c) 2004-2010 All Rights Reserved.
 */
package com.zhz.lib.cms.manage;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.zhz.lib.cms.utils.zhz.ZhzReflectionUtil;
import com.zhz.project.common.util.alibaba.StringUtil;
import com.zhz.project.common.util.zhzutil.ZhzHttpRequestUtil;

/**
 * 具有审核功能的模块的基类
 *
 * @author liwei2672
 * @version $Id: BaseAction.java, v 0.1 2010-7-17 下午03:18:15 liwei2672 Exp $
 */
public class BaseActionWithApprove extends BaseActionWithSearch {

    /**
     * 根据选择的审核状态构造查询语句
     *
     * @param request
     * @param table
     * @param key
     * @param entryTatal
     * @param whereStatement
     * @param LIST
     */
    @Override
    @SuppressWarnings("unchecked")
    protected List getListWithFanyeHref(HttpServletRequest request, final String table,
                                        String whereStatement, final String order, String list,
                                        StringBuffer fanyeHref) {
        // 取出选择的审核状态
        String radiooption = ZhzHttpRequestUtil.getParameters(request, "radiooption");

        if (StringUtil.isNotBlank(radiooption)) {
            if (StringUtil.equals(radiooption, "weishenhe")) {
                whereStatement += " and   aproveState=" + 0;
            } else if (StringUtil.equals(radiooption, "yitongguo")) {
                whereStatement += " and   aproveState=" + 1;
            } else if (StringUtil.equals(radiooption, "weitongguo")) {
                whereStatement += " and   aproveState=" + 2;
            }
            fanyeHref.append("&radiooption=");
            fanyeHref.append(radiooption);
        }

        request.setAttribute("radiooption", ZhzHttpRequestUtil
            .getParameters(request, "radiooption"));

        return super.getListWithFanyeHref(request, table, whereStatement, order, list, fanyeHref);

    }

    /**
     *对选择的记录进行审核，通过反射实现，在事务中进行 <br/>
     *要求对象具有 setAproveState setAproveTime setEditor方法<br/>
     * 其中 <br/>
     * setAproveState用来设置审核值<br/>
     * setAproveTime用来设置审核时间<br/>
     * setEditor用来设置审核操作员<br/>
     * 
     * @param request
     * @param table 表名
     * @param key   字段名称
     */
    protected void approveRecord(HttpServletRequest request, final String table, final String key) {
        ZhzReflectionUtil.approveRecord(request, transactionTemplate, baseDao, table, key);
    }

}
